from typing import List

from fastapi import Path, Depends, Query

from app.core.BaseResponse import success
from app.model import mysql
from app.service import mine_service, user as user_service
from app.service.jwt_service import get_current_user
from app.validator.app import schemas


async def logout(
        current_user: schemas.User = Depends(get_current_user),
):
    """
    退出登陆
    :param current_user:
    :return:
    """
    await mine_service.logout(current_user)
    return success()


async def detaction_version(
        current_user: schemas.User = Depends(get_current_user),
):
    """
    版本检测
    :param current_user:
    :return:
    """
    return

async def get_interest_tags(
        current_user: schemas.User = Depends(get_current_user),
):
    """
    获取兴趣标签
    :param current_user:
    :return:
    """
    tags = await mine_service.get_interest_tags(current_user)
    return success(tags)


async def save_interest_tags(
        tags: List[schemas.SaveInterestTags],
        current_user: schemas.User = Depends(get_current_user),
):
    """
    保存兴趣标签
    :param tags:
    :param current_user:
    :return:
    """
    await mine_service.save_interest_tags(tags, current_user)
    return success()


async def enshrine(
        enshrines_id: int = Path(...),
        current_user: schemas.User = Depends(get_current_user),
):
    """
    收藏
    :param enshrines_id: 媒体id
    :param current_user:
    :return:
    """
    await mine_service.enshrine(enshrines_id, current_user)
    return success()


async def del_enshrine(
        enshrines_id: int = Path(...),
        current_user: schemas.User = Depends(get_current_user),
):
    """
    取消收藏
    :param enshrines_id:
    :param current_user:
    :return:
    """
    await mine_service.del_enshrine(enshrines_id, current_user)
    return success()


async def followers_list(
        page: int = Query(1),
        current_user: schemas.User = Depends(get_current_user),
):
    """
    获取关注列表
    :param page:
    :param current_user:
    :return:
    """
    follow_list = await mine_service.followers_list(page, current_user)
    return success(follow_list)


async def followers(
        follow_user_id: int = Path(...),
        current_user: schemas.User = Depends(get_current_user),

):
    """
    关注
    :param follow_user_id:
    :param current_user:
    :return:
    """
    await mine_service.followers(follow_user_id, current_user)
    return success()


async def del_followers(
        follow_user_id: int = Path(...),
        current_user: schemas.User = Depends(get_current_user),

):
    """
    取消关注
    :param follow_user_id:
    :param current_user:
    :return:
    """
    await mine_service.del_followers(follow_user_id, current_user)
    return success()


async def fans(
        page: int = Query(1),
        current_user: schemas.User = Depends(get_current_user),
):
    """
    粉丝列表
    :param page:
    :param current_user:
    :return:
    """
    fan_list = await mine_service.fans(page, current_user)
    return success(data=fan_list)


async def like_list(
        page: int = Query(1),
        current_user: schemas.User = Depends(get_current_user),
):
    """
    点赞列表
    :param page:
    :param current_user:
    :return:
    """
    result = await mine_service.like_list(page, current_user)
    return success(result)


async def likes(
        like_id: int = Path(...),
        current_user: schemas.User = Depends(get_current_user),
):
    """
    点赞
    :param like_id: 点赞媒体id
    :param current_user:
    :return:
    """
    await mine_service.likes(like_id, current_user)
    return success()


async def del_likes(
        like_id: int = Path(...),
        current_user: schemas.User = Depends(get_current_user),
):
    """
    取消点赞
    :param like_id: 点赞媒体id
    :param current_user:
    :return:
    """
    await mine_service.del_likes(like_id, current_user)
    return success()


async def comment_list(
        page: int = Query(1),
        current_user: object = Depends(get_current_user),
):
    """
    评论列表
    :param page:
    :param current_user:
    :return:
    """
    comments = await mine_service.comment_list(page, current_user)
    return success(comments)


async def comment_like(
        like_id: int = Path(...),
        current_user: schemas.User = Depends(get_current_user),
):
    """
    评论点赞
    :param like_id:
    :param current_user:
    :return:
    """
    await mine_service.comment_like(like_id, current_user)
    return success()


async def comment_del_like(
        like_id: int = Path(...),
        current_user: schemas.User = Depends(get_current_user),
):
    """
    取消点赞评论
    :param like_id:
    :param current_user:
    :return:
    """
    await mine_service.comment_del_like(like_id, current_user)
    return success()


async def custom_tag_list(
        current_user: schemas.User = Depends(get_current_user)
):
    """
    获取自定义标签
    :param current_user:
    :return:
    """
    tags = await user_service.get_user_custom_tags(current_user.id)
    response_tags = [{"name": item, "type": 2} for item in tags]
    return success(response_tags)


async def add_custom_tags(
        tag: schemas.CustomTag,
        current_user: schemas.User = Depends(get_current_user)
):
    """
    新增自定义标签
    :type tag: 标签
    :param current_user:
    :return:
    """
    await user_service.add_user_custom_tags(current_user.id, [tag.tag])
    return success()


async def del_custom_tags(
        tag: schemas.CustomTag,
        current_user: schemas.User = Depends(get_current_user),
):
    """
    删除自定义标签
    :param tag: 标签
    :param current_user:
    :return:
    """
    await mine_service.del_custom_tags([tag.tag], current_user)
    return success()


async def enshrine_list(
        page: int = Query(1),
        current_user: schemas.User = Depends(get_current_user),
):
    """
    收藏列表
    :param page:
    :param current_user:
    :return:
    """
    result = await mine_service.enshrine_list(page, current_user)
    return success(result)


async def message_kind_list(
        page: int = Query(1),
        current_user: schemas.User = Depends(get_current_user),
):
    """
    消息类型列表
    :param page: 页数
    :param current_user: 当前用户
    :return:
    """
    result = await mine_service.message_kind_list(page, current_user)
    return success(result)


async def kind_message_list(
        kid: int = Path(...),
        page: int = Query(1),
        current_user: schemas.User = Depends(get_current_user),
):
    """
    消息类型列表
    :param kid:
    :param page:
    :param current_user: 当前用户
    :return:
    """
    result = await mine_service.kind_message_list(kid, page, current_user)
    return success(result)


async def get_user_info(
        current_user: schemas.User = Depends(get_current_user),
):
    """
    获取编辑个人资料
    :param current_user:
    :return:
    """
    result = await mine_service.get_user_info(current_user)
    return success(result)


async def update_user_info(
        user_info: schemas.UserInfo,
        current_user: schemas.User = Depends(get_current_user),
):
    """
    更新编辑个人资料
    :param user_info:
    :param current_user:
    :return:
    """
    await mine_service.update_user_info(user_info, current_user)
    return success()


async def user_home(
        current_user: schemas.User = Depends(get_current_user)
):
    """
    个人主页信息
    :param current_user:
    :return:
    """
    result = await mine_service.user_home(current_user)
    return success(result)


async def history_list(
    page: int = Query(1),
    current_user: schemas.User = Depends(get_current_user)
):
    """
    浏览记录列表
    :param page:
    :param current_user:
    :return:
    """
    result = await mine_service.history_list(page, current_user)
    return success(result)


async def get_mobile(
        current_user: schemas.User = Depends(get_current_user)
):
    """
    获取当前用户手机号
    :param current_user:
    :return:
    """
    result = {"mobile": current_user.mobile}
    return success(result)


async def val_old_mobile(
        user: schemas.LoginVal,
        current_user: schemas.User = Depends(get_current_user)
):
    """
    获取当前用户手机号
    :param user:
    :param current_user:
    :return:
    """
    result = await mine_service.val_old_mobile(user, current_user)
    return success(result)


async def val_new_mobile(
        user: schemas.UpdateMobile,
        current_user: schemas.User = Depends(get_current_user)
):
    """
    获取当前用户手机号
    :param user:
    :param current_user:
    :return:
    """
    await mine_service.val_new_mobile(user, current_user)
    return success()


async def check_version(
        current_user: schemas.User = Depends(get_current_user)
):
    """
    版本检测
    :return:
    """
    result = {
        "latestVersion": "2.0",
        "minVersion": "1.0",
        "androidUrl": "https://www.baidu.com/",
        "iosUrl": "https://www.baidu.com/",
        "desc": "1、新增xxxx功能/r/n2、修复bug"
    }
    return success(result)
